﻿<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>

<script language="VB" runat="server">

    Public Sql As String = "SELECT * FROM jgbbs_posts" _
         , cmd As OleDbCommand = New OleDbCommand(Sql, global_asax.conn1) _
         , da As OleDbDataAdapter = New OleDbDataAdapter() _
         , ds As DataSet = New DataSet() _
         , Table As DataTable _
         , IRow As DataRow
    
    Structure _meta
        Dim _meta_title As String _
          , _meta_description As String _
          , _meta_keywords As String _
          , _meta_LI As String
    End Structure
    
    Function GET_PAGE_INFO(ByVal [_PAGE_PATH] As String) As _meta
        Dim ret As _meta = New _meta
        Try
            Dim [_XML_DATA] As String _
                    = global_asax.GetInfo([_PAGE_PATH]) _
              , [_NEW_XML_DATA] As String = Nothing

            [_XML_DATA] = [_XML_DATA].Replace(ControlChars.NewLine, "").Replace(ControlChars.CrLf, "") _
                                     .Replace("<!--", "").Replace("-->", "")
            Dim TAGS As Dictionary(Of String, Integer) _
                  = New Dictionary(Of String, Integer)
            Dim MC As System.Text.RegularExpressions.MatchCollection _
                    = New Regex(String.Concat("<", "(.*?)")).Matches([_XML_DATA])
            Dim ITab As Integer = 0
            Dim LI1 As Integer = 0
            Dim LI2 As Integer = 0
            For i As Integer = 0 To MC.Count - 1
                Dim T1 As Integer = 0 _
                  , T2 As Integer = 0
                Try
                    T1 = MC(i + 0).Index
                    T2 = MC(i + 1).Index
                Catch ex As Exception
                    T1 = MC(i + 0).Index
                    T2 = [_XML_DATA].Length
                End Try
                Dim substring As String = [_XML_DATA].Substring(T1, T2 - T1).ToLower.Replace(ControlChars.Tab, "") _
                                                                                    .Replace(ControlChars.NullChar, "") _
                                                                                    .Replace(ControlChars.CrLf, "") _
                                                                                    .Replace(ControlChars.Cr, "")
                If global_asax.CheckTags2(substring, "<title>") > 0 Then
                    ret._meta_title = substring.Replace("<title>", "")
                End If
                If global_asax.CheckTags2(substring, "description") > 0 Then
                    ret._meta_description = substring.Substring(global_asax.CheckTags(substring, "content=") + 9).Replace("""", "") _
                                                                                                                 .Replace("`", "") _
                                                                                                                 .Replace("/", "") _
                                                                                                                 .Replace(">", "") _ 
                                                                                                                 .Replace("'", "")
                End If
                If global_asax.CheckTags2(substring, "keywords") > 0 Then
                    ret._meta_keywords = substring.Substring(global_asax.CheckTags(substring, "content=") + 9).Replace("""", "") _
                                                                                                              .Replace("`", "") _
                                                                                                              .Replace("/", "") _
                                                                                                              .Replace(">", "") _ 
                                                                                                              .Replace("'", "")
                End If
               
            Next

            '[_XML_DATA] = [_XML_DATA].ToLower.Replace(ControlChars.Tab, "") _
            '                                 .Replace(ControlChars.NullChar, "") _
            '                                 .Replace(ControlChars.CrLf, "") _
            '                                 .Replace(ControlChars.Cr, "")
            'If global_asax.CheckTags2([_XML_DATA], "<ul") > 0 Then
            '    LI1 = global_asax.CheckTags([_XML_DATA], "<ul")
            'End If
            'If global_asax.CheckTags2([_XML_DATA], "</ul>") > 0 Then
            '    LI2 = global_asax.CheckTags3([_XML_DATA], "</ul>")
            'End If
            'If (LI1 > 0) And (LI2 > 0) Then
            '    Dim [_str] As String = Nothing
            '    Dim [_DATA] As Byte() _
            '            = Encoding.UTF8.GetBytes(String.Concat([_XML_DATA].Substring(LI1, LI2 - LI1), "</ul>"))
            '    For Each b As Byte In [_DATA]
            '        [_str] = String.Concat([_str], b, " ")
            '    Next
            '    ret._meta_LI = [_str].Replace("{", "").Replace("}", "") _
            '                         .Replace("\", "").Replace("/", "") _
            '                         .Replace("|", "").Replace("~", "")
            '    ret._meta_LI = ret._meta_LI.Replace("`", "").Replace("'", "").Replace("+", "").Replace("-", "")
            'End If
                        
        Catch ex As Exception
        End Try
        Return ret
    End Function
    
    Public Sub Inicialize()
        With da
            .SelectCommand = cmd
            .Fill(ds, "ALL_RSS")
        End With
        Table = ds.Tables(0)
        '------------------
        Dim foundRows() As DataRow _
             = Table.Select(Nothing, "RATE DESC")
        Dim ITemp As DataTable = Table.Copy()
        ITemp.Rows.Clear()
        For Each r As DataRow In foundRows
            ITemp.ImportRow(r)
        Next
        Table = ITemp
        '------------------
    End Sub
    
    Public CAT As Dictionary(Of String, String) _
            = New Dictionary(Of String, String)
    
    Sub GET_CATS()
        '
        '
    End Sub
    
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        '
        Try
            '
            HttpContext.Current.Session("ERROR") = Nothing 
            '
        Catch ex As Exception
        End Try
        '
    End Sub
    
    Sub Selection_Change(ByVal sender As Object, ByVal e As EventArgs)
        '
        '
    End Sub

    Protected Sub PROCESSING_IT(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not IsNothing(HttpContext.Current.Session("USED")) Then
            '
            Dim ERR As String = Nothing 
            Try
                Dim [T] As String = Nothing
                Try
                    [T] = I_URL.Text.ToLower.Trim.Split(",")(0)
                Catch ex As Exception
                    [T] = I_URL.Text.ToLower
                End Try
                '
                Dim [URI] As Uri _ 
                       = New Uri([T])
                If [URI].AbsolutePath.Split("/").Count > 4 Then
                    ERR="URL: It`s Long url!"
                End If
                Dim _TYPE As String = "http://"  
                If [T].Substring(0 ,8) = "https://"
                    _TYPE = "https://"
                End If
                [T]=String.Concat(_TYPE, [URI].Host, [URI].AbsolutePath.Replace("//","") _ 
                                                                       .Replace("//","") _ 
                                                                       .Replace("//",""))
                Dim ret As _meta = Nothing 
                ret.ToString.ToLower 
                Try
                    ret = GET_PAGE_INFO([T])
                    If ret._meta_title.Length < 4 Then
                        ERR=String.Concat("Request: not connect`ed to:", [T])
                    End If
                Catch ex As Exception
                    ERR=String.Concat("Request: not connect`ed to:", [T])
                End Try
                '
                If IsNothing(ERR) Then
                    Dim cmd2 As New OleDbCommand()
                    cmd2.Connection = global_asax.conn1
                    Dim query As String _
                            = String.Concat("INSERT INTO ALL_RSS ( link, TITLE, TAGS, DESCRIPTION, RATE, LI ) values ('", [T], "', '", ret._meta_title, "', '", ret._meta_keywords, "', '", ret._meta_description, "', ", 1, ", '", ret._meta_LI, "')")
                    If CB_ADALT.Checked 
                        query = String.Concat("INSERT INTO ALL_RSS ( link, TITLE, TAGS, DESCRIPTION, RATE, LI, ADL ) values ('", [T], "', '", ret._meta_title, "', '", ret._meta_keywords, "', '", ret._meta_description, "', ", 1, ", '", ret._meta_LI, "', True)")   
                    End If
                    cmd2.CommandText = query
                    cmd2.ExecuteNonQuery()
                    '
                    Sql = String.Concat("SELECT * FROM ALL_RSS WHERE link Like '%", [T], "%'")
                    cmd = New OleDbCommand(Sql, global_asax.conn1)
                    Inicialize()
                    Try
                        Select Case Table.Rows.Count
                            Case 1
                                Response.Redirect(String.Concat("?ID=", Table.Rows(0)("ID")))
                            Case Is > 1
                                Dim ARR As ArrayList _
                                     = New ArrayList
                                For i As Integer = 1 To Table.Rows.Count - 1
                                    ARR.Add(Table.Rows(i))
                                Next
                                HttpContext.Current.Session.Add("FIND_ARRAY", ARR)
                                Response.Redirect("FIND.ASPX")
                        End Select
                    Catch ex As Exception
                        ERR=String.Concat("ERROR PAGE PARSE`r | ", ex.Message)
                    End Try
                End If
                '
            Catch ex As Exception
                ERR=String.Concat("ERROR PAGE PARSE`r | ", ex.Message)
            End Try
            '
            If NOT IsNothing(ERR) Then
                HttpContext.Current.Session.Add("ERROR", ERR)
            End If
            '
        End If
        I_URL.Text = ""
    End Sub
    
</script>

<%@ Page Title="Submit to directory" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="Add.aspx.vb" Inherits="Add" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">

    <%
        If NOT IsNothing(HttpContext.Current.Session("ERROR")) Then
                 Response.Redirect("ERRORS.ASPX")
        Else
            %>
          
                        
            <%  
        End If
    %>



              <%--------------------------------%>
              <%
                  GET_CATS()
              %>
              <br />

                <p>
                <span  style="background-color: #FFFF00;"><strong>WARNING:</strong></span><br />
                <ul><li>
                    <span  style="color: #800000;"><strong>By lowering the rating to -4 automatically removes 
                    the article</strong></span>
                </li><li>
                    <span  style="color: #800000;"><strong>ONLY LOW`er CASE URL!</strong></span>
                </li></ul>
                </p>

                                      <asp:Panel ID="Panel2" runat="server" 
                                          BorderStyle="Solid" Height="100px" 
                                          Width="366px" BorderColor="Black" 
                                          BackColor="#CCCCCC">
                                          &nbsp;URL:<br />
                                          <asp:TextBox ID="I_URL" runat="server" BorderStyle="Solid" Width="346px"></asp:TextBox>
                                          <br />
                                          <asp:CheckBox ID="CB_ADALT" runat="server" BorderColor="#66CCFF" 
                                              ForeColor="#990000" Text="It Adult?" />
                                          <br />
                                          <asp:Button ID="Processing" runat="server" Text="SAVE"  OnClick="PROCESSING_IT" 
                                              AutoPostBack="True" />
                                          <br />
                                      </asp:Panel>
                <br /><br /><br /><br /><br /><br />
              <%--------------------------------%>	


</asp:Content>

